package com.yunchao.library.socket.model.connection


import com.yunchao.library.socket.extensions.toReadOnlyBuffer

data class EnvironmentCheck(
    val error: String = ""
) {
    companion object {
        fun fromByteArray(bytes: ByteArray): EnvironmentCheck {
            val buffer = bytes.toReadOnlyBuffer()
            val length = buffer.int
            val error = if (length > 0) {
                val data = ByteArray(length)
                buffer.get(data)
                String(data, Charsets.UTF_8)
            } else ""
            return EnvironmentCheck(error)
        }
    }
}